/*
 * Achieve it All! - Android app to motivate achieving your goals
 * Copyright (C) 2014  Xilconic
 * 
 * This file is part of Achieve it All!.
 *
 * Achieve it All! is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Achieve it All! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Achieve it All!.  If not, see <http://www.gnu.org/licenses/>
 */
package com.xilconic.achieveitall.fragments;

import com.xilconic.achieveitall.R;
import com.xilconic.achieveitall.domain.Target;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.EditText;

public class TargetDetailFragment extends Fragment {
    private Target target;
    private EditText nameEditText, descriptionEditText;
    
    /**
     * {@link Fragment} argument representing the {@link Target} being
     * visualized in this fragment.
     */
    private static final String ARG_TARGET = "target";
    /**
     * Creates a new {@link TargetDetailFragment} to edit a given {@link Target}.
     * @param target The target to edit.
     * @return The fragment to edit the target in.
     */
    public static TargetDetailFragment newInstance(Target target) {
        if(target == null){
            throw new IllegalArgumentException("'target' cannot be null.");
        }
        
        TargetDetailFragment fragment = new TargetDetailFragment();
        
        Bundle args = new Bundle();
        args.putParcelable(ARG_TARGET, target);
        fragment.setArguments(args);
        
        return fragment;
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_target,
                container, false);
        
        Bundle arguments = getArguments();
        target = (Target)arguments.getParcelable(ARG_TARGET);

        return rootView;
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        
        nameEditText = (EditText)getView().findViewById(R.id.target_name_EditText);
        nameEditText.setText(target.getName());
        
        descriptionEditText = (EditText)getView().findViewById(R.id.target_description_EditText);
        descriptionEditText.setText(target.getDescription());
        
        CheckBox checkBox = (CheckBox)getView().findViewById(R.id.target_isFinished_CheckBox);
        checkBox.setChecked(target.isFinished());
    }

    @Override
    public void onPause(){
        super.onPause();
    }
}
